<?php

$current_page = 'login';

include 'inc_header.php';
include 'inc_menu.php';

//Redirect if User is not logged on
if(!isset($_SESSION["username"]))
{
	header("location: index.php");
}

//Check if user has to be deleted
if(@$_REQUEST['action']=="dellogin")
{
	$connection = new DAOmySQLi();
	$connection->deleteLogin();
}

//Check if there is a new user is to insert
if(isset($_POST['insertlogin']))
{
	$connection = new DAOmySQLi();
	$connection->insertLogin();
}
?>

<div id="main">
	<div class="ym-wrapper">
		<div class="ym-wbox">

			<h3>Setup Login</h3>
			<form class="ym-form ym-columnar linearize-form" action=login.php method=post enctype=multipart/form-data>
				<div class="ym-fbox-text">
					<label for="username">Username:</label> <input type="text" name="insertusername" id="insert-text" />
				</div>
				<div class="ym-fbox-text">
					<label for="displayname">Display Name:</label> <input type="text" name="insertdisplayname" id="insert-text" />
				</div>
				<div class="ym-fbox-text">
					<label for="password">Password:</label> <input type="password" name="insertpassword" id="insert-text" />
				</div>

				<div class="ym-fbox-text">
					<label for="your-id">Status</label> 
					<select name="dropdown_status" size="1" id="insert-dropdown">
						<option value="0">Inactive</option>
						<option value="1">Active</option>
					</select>
				</div>

				<div class="ym-fbox-button">
					<button class="ym-button ym-add" type="submit" name="insertlogin" id="insert-button">Insert</button>
				</div>
			</form>

			<h3>Edit existing Login</h3>

			<?php
				//Show current users
				$connection = new DAOmySQLi();
				$connection->getLoginData();
			?>						
					
		</div>
	</div>
</div>

<?php
include 'inc_footer.php';
?>